package com.efast.dmom.mes.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.dmom.mes.bean.ProductionImplementationAccept;
import com.efast.dmom.mes.dao.entity.ProductionPiecePartDao;
import com.efast.dmom.mes.entity.ProductionPiecePartEntity;
import com.efast.dmom.mes.service.ProductionPiecePartService;
import com.efast.dmom.mes.util.SpringWebUtils;
import com.efast.dmom.mes.util.TimeUtil;

@Service
public class ProductionPiecePartServiceImpl implements ProductionPiecePartService {

	@Autowired
	private ProductionPiecePartDao productionPiecePartDao;

	@Override
	public List<ProductionPiecePartEntity> getProductionPiecePartList(ProductionImplementationAccept acceptBean) {
		List<ProductionPiecePartEntity> productionPiecePartEntityList = productionPiecePartDao
				.getProductionPiecePartList(acceptBean.getPartId(), acceptBean.getOperationId(),acceptBean.getUser());
		return productionPiecePartEntityList;
	}
 
	@Override
	public void submittedWorkByPiecePart(ProductionPiecePartEntity productionPiecePartEntity) {
		ProductionPiecePartEntity piecePartEntity = productionPiecePartDao
				.getProductionPiecePartByPartIdAndOperationId(productionPiecePartEntity);
		if (piecePartEntity != null) {
			piecePartEntity.setLastModifiedTime(TimeUtil.getLocalDateTime());
			piecePartEntity.setLastModifier(SpringWebUtils.getRequestUser());
			piecePartEntity.setIsFlag(1);
			productionPiecePartDao.update(piecePartEntity);
		}
		productionPiecePartDao.save(productionPiecePartEntity);
	}

	@Override
	public ProductionPiecePartEntity getProductionPiecePart(ProductionImplementationAccept acceptBean) {
		ProductionPiecePartEntity productionPiecePartEntity = productionPiecePartDao.getProductionPiecePart(acceptBean);
		return productionPiecePartEntity;
	}

	@Override
	public void save(ProductionPiecePartEntity productionPiecePartEntity) {
		productionPiecePartDao.save(productionPiecePartEntity);
	}

}
